package com.kuang.config;


import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Configuration和spring的xml配置文件一样，配置beans用bean注解
 * 启动在spring的xml配置文件中beans标签里的id属性对应这里的方法名restHighLevelClient
 * class属性对应这里的RestHighLevelClient
 *
 *
 *
 * 狂神spring两个步骤
 * 1.找对象
 * 2.放到spring容器中待用
 * 3.如果是springboot分析源码
 *    xxxAutoconfiguration自动配置   xxxproperties配置类
 */
@Configuration
public class ElasticSearchClientConfig {


    /**
     * 如果是集群就创建多个
     * @return
     */
    @Bean
    public RestHighLevelClient restHighLevelClient(){
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(
                  new HttpHost("127.0.0.1", 9200, "http")));
//                        new HttpHost("localhost", 9201, "http")));
        return client;
    }
}
